package com.woniu.model.healthSystem.entity;

import lombok.Data;

import java.util.List;

@Data
public class PageBean<T> {
    private List<T> data; //一页显示的数据
    private int count;  //一共有多少条记录
    private int size;  //每页大小
    private int total;  //总页数

    private int current;  //当前页

    private int first; //第一页
    private int next;  //下一页
    private int previous;  //上一页
    private int last; //最后一页

    public int getFirst() {
        return 1;
    }

    public PageBean() {
    }

    public PageBean(List<T> data, int count, int size, int current) {
        this.data = data;
        this.count = count;
        this.size = size;
        this.current = current;
    }

    public int getCurrent() {
        return current;
    }

    //下一页
    public int getNext() {
        if (getCurrent() < getTotal()) {
            return getCurrent() + 1;
        } else {
            return getTotal();
        }
    }

    //上一页
    public int getPrevious() {
        if (getCurrent() > getFirst()) {
            return getCurrent() - 1;
        } else {
            return getFirst();
        }
    }

    //最后一页
    public int getLast() {
        return getTotal();
    }

    /*
        计算总页数：如果能整除就正好是这么多页，不能整除就加1
         */
    public int getTotal() {
        return getCount() % getSize() == 0 ?
                getCount() / getSize() :
                getCount() / getSize() + 1;
    }
}
